package com.scanner.hardware;

import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;
import android.support.multidex.MultiDex;
import android.util.DisplayMetrics;
import android.util.Log;
import android.util.Xml;
import android.view.WindowManager;

import com.scanner.Data.BeanData;
import com.scanner.bean.BrocastButton;
import com.scanner.bean.Constans;
import com.scanner.bean.MotoBarcode;
import com.scanner.bean.MotoQRBarcode;
import com.scanner.bean.ScanSetting;
import com.scanner.hardware.db.helper.DaoHelper;
import com.scanner.util.BaseUtils;
import com.scanner.util.LogUtil;
import com.scanner.util.SharePreConfig;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class MyApplication extends Application{
	/**
	 * 全局使用线程池
	 * 网络请求、耗时等线程操作均放入线程测操作
	 */
	public static ExecutorService actionThreadPool = Executors.newFixedThreadPool(5);

	public static final String Tag = "MyApplication";
        public static final String SYMBOL_CONFIG_SIG =  "com.android.barcodescanner.sig";
        public static final String SYMBOL_CONFIG_QR  =  "com.android.barcodescanner.qr";
        public static final String SCAN_MODE_SIG     =  "com.android.barcodescanner.scanmodesig";
        public static final String SCAN_MODE_LEFT    =  "com.android.barcodescanner.leftenable";
        public static final String SCAN_MODE_RIGHT    =  "com.android.barcodescanner.rightenable";
        public static final String SCAN_TIME_OUT     =  "com.android.barcodescanner.timeout";
        
        public static final String MODUL_INIITED     =  "com.android.barcodescanner.init";
        public static final String FIRST_INSTALL     =  "com.android.barcodescanner.firstinstall";
        public static final String FACTORY_DEFAULT   =  "defalt.";
        public static final byte [] FACTORY_MOTORESULT = {0X07, (byte) 0XC6,0X04,0X00, (byte) 0XFF, (byte) 0X8A,0x08, (byte) 0xFD, (byte) 0x9E};//{0x04, (byte) 0xe4,0x04,0x00, (byte) 0xff,0x14};
        public static boolean onSettings = false;
	/*Leon:
	自动感应    07 C6 04 00 FF 8A 07 FD 9F

	Leon:
	Host   07 C6 04 00 FF 8A 08 FD 9E*/
	public static final byte[] ALWAYSLINGHTTRUE = {0x07, (byte) 0xC6,0x04,0x00, (byte) 0xFF, (byte) 0x8A,0x07, (byte) 0xFD, (byte) 0x9F};

	public static final byte[] ALWAYSLINGHTFALSE= {0x07, (byte) 0xC6,0x04,0x00, (byte) 0xFF, (byte) 0x8A,0x08, (byte) 0xFD, (byte) 0x9E};

	public static final String ACTION_SERIALPORT_SERVICE = "android.intent.action.BOOT_SERIALPORT_SERVICE";
    	
    private String[] symbolsSig = {				//一维码制名称
    			"Straight 2 of 5 IATA", "China Post", "codebar", "code 11",
    			"Code 128",  "code 32 Pharmaceutical",  "Code 39",  "code 93", 
    			"EAN/JAN-13", "EAN/JAN-8",  "GS1 DataBar Expanded", "GS1 DataBar Limited", 
    			"GS1 DataBar Omnidirectional",  "GS1-128",  "Interleaved 2 of 5", "ISBT 128", 
    			"Matrix 2 of 5",  "MSI",  "NEC 2 of 5",  "Plessey Code", 
    			"Postal Codes", "Straight 2 of 5 Industrial",  "Telepen",  "Trioptic Code",
    			"UPC-A/EAN-13(Allow Concatenation)", "UPC-A/EAN-13(Require Concatenation)", "UPC-E0",  "GS1-128 Emulation", 
    			"GS1 DataBar Emulation",  "GS1 Code Expansion Off",  "EAN8 to EAN13 Conversion"
    			};
    
    private String[] commandsSig = {		//一维码制命令
    			"a25ena1.",  "cpcena1.", "cbrena1.",  "c11ena1.",
    			"128ena1.",  "c39b321.", "c39ena1.",  "c93ena1.",
    			"e13ena1.",  "ea8ena1.", "rseena1.",  "rslena1.",
    			"rssena1.",  "gs1ena1.", "i25ena1.",  "isbena1.",
    			"x25ena1.",  "msiena1.", "n25ena1.",  "plsena1.",
    			"cpcena1.",  "r25ena1.", "telena1.",  "triena1.",
    			"cpnena1.",  "cpnena2.", "upeen01.",  "eanemu1.",
    			"eanemu2.",  "eanemu3.", "eanemu4."
    			};
    
    private String[] commandsSig_default = {	//一维默认码制
				"a25ena0.",  "cpcena0.", "cbrena1.",  "c11ena0.",
				"128ena1.",  "c39b320.", "c39ena1.",  "c93ena1.",
				"e13ena1.",  "ea8ena1.", "rseena1.",  "rslena1.",
				"rssena1.",  "gs1ena1.", "i25ena1.",  "isbena0.",
				"x25ena0.",  "msiena0.", "n25ena0.",  "plsena0.",
				"cpcena0.",  "r25ena0.", "telena0.",  "triena0.",
				"cpnena0.",  "cpnena0.", "upeen01.",  "eanemu0.",
				"eanemu0.",  "eanemu0.", "eanemu0."
	};
    
     private String[] symbolsQR = {			//二维码制名称
			    "Aztec Code",  "China Post (Hong Kong 2 of 5)",  "Chinese Sensible (Han Xin) Code",  "Codabar",
			    "Codablock A",  "Codablock F",  "Code 11",  "Code 128",
                "Code 32 Pharmaceutical (PARAF)", "Code 39",  "Code 93",  "Data Matrix",
                "EAN/JAN-13",  "EAN/JAN-8",  "GS1 Composite Codes",  "GS1 DataBar Expanded",
                "GS1 DataBar Limited",  "GS1 DataBar Omnidirectional",  "GS1-128 Emulation", "GS1 DataBar Emulation",
                "GS1 Code Expansion Off", "EAN8 to EAN13 Conversion",  "GS1-128",  "Interleaved 2 of 5",
                "Korea Post",  "Matrix 2 of 5",  "MaxiCode",  "MicroPDF417",
                "MSI",  "NEC 2 of 5",  "China Post (Hong Kong 2 of 5)", "Korea Post",
                "Korea Post Check Digit",  "PDF417",  "QR Code",  "Straight 2 of 5 IATA (two-bar start/stop)", 
                "Straight 2 of 5 Industrial (three-bar start/stop)",  "TCIF Linked Code 39 (TLC39)",  "UPC-A",  "UPC-A/EAN-13 with Extended Coupon Code(Allow Concatenation)", 
                "UPC-A/EAN-13 with Extended Coupon Code(Require Concatenation)", "UPC-E0",  "UPC-E1"
	};
	private String[] commandsQR = {		//二维码制命令
			    "aztena1.", "cpcena1.", "hx_ena1.", "cbrena1.",
                "cbaena1.", "cbfena1.", "c11ena1.", "128ena1.",
                "c39b321.", "c39ena1.", "c93ena1.", "idmena1.",
                "e13ena1.", "ea8ena1.", "comena1.", "rseena1.",
                "rslena1.", "rssena1.", "eanemu1.", "eanemu2.",
                "eanemu3.", "eanemu4.", "gs1ena1.", "i25ena1.",
                "kpcena1.", "x25ena1.", "maxena1.", "mpdena1.",
                "msiena1.", "n25ena1.", "cpcena1.", "kpcena1.",
                "kpcchk1.", "pdfena1.", "qrcena1.", "a25ena1.", 
                "r25ena1.", "t39ena1.", "upbena1.", "cpnena1.", 
                "cpnena2.", "upeen01.", "upeen11."
	}; 
	private String[] commandsQR_default = {		//二维默认码制
			    "aztena1.", "cpcena0.", "hx_ena0.", "cbrena1.",
	            "cbaena0.", "cbfena0.", "c11ena0.", "128ena1.",
	            "c39b320.", "c39ena1.", "c93ena1.", "idmena1.",
	            "e13ena1.", "ea8ena1.", "comena0.", "rseena1.",
	            "rslena1.", "rssena1.", "eanemu0.", "eanemu0.",
	            "eanemu0.", "eanemu0.", "gs1ena1.", "i25ena1.",
	            "kpcena0.", "x25ena0.", "maxena0.", "mpdena0.",
	            "msiena0.", "n25ena1.", "cpcena0.", "kpcena0.",
	            "kpcchk0.", "pdfena1.", "qrcena1.", "a25ena0.", 
	            "r25ena0.", "t39ena0.", "upbena1.", "cpnena0.", 
	            "cpnena0.", "upeen01.", "upeen10."
    };

	//摩托一维码名称
	private String[] motoSigName = {"UPC A","UPC E","UPC E1","EAN-8/JAN 8","Code 128","Code 39","Code 93","Code 11","Interleaved 2 of 5","Codabar",
			"GS1 DataBar-14"};
	//摩托二维码默认值
	private int[] motoSig_default = {1,1,0,1,1,1,1,0,0,1,1};

	//摩托一维码码制（开）
	private byte[][] motoSigValueOpen = {{0x07, (byte) 0xC6,0x04,0x00, (byte) 0xFF,0x01,0x01, (byte) 0xFE,0x2E},{0x07, (byte) 0xC6,0x04,0x00, (byte) 0xFF,0x02,0x01, (byte) 0xFE,0x2D},
			{0x07, (byte) 0xC6,0x04,0x00, (byte) 0xFF,0x0C,0x01, (byte) 0xFE,0x23},{0x07, (byte) 0xC6,0x04,0x00, (byte) 0xFF,0x04,0x01, (byte) 0xFE,0x2B},{0x07, (byte) 0xC6,0x04,0x00, (byte) 0xFF,0x08,0x01, (byte) 0xFE,0x27},
			{0x07, (byte) 0xC6,0x04,0x00, (byte) 0xFF,0x00,0x01, (byte) 0xFE,0x2F},{0x07, (byte) 0xC6,0x04,0x00, (byte) 0xFF,0x09,0x01, (byte) 0xFE,0x26},{0x07, (byte) 0xC6,0x04,0x00, (byte) 0xFF,0x0A,0x01, (byte) 0xFE,0x25},
			{0x07, (byte) 0xC6,0x04,0x00, (byte) 0xFF,0x06,0x01, (byte) 0xFE,0x29},{0x07, (byte) 0xC6,0x04,0x00, (byte) 0xFF,0x07,0x01, (byte) 0xFE,0x28},
			{0x07, (byte) 0xC6,0x04,0x00, (byte) 0xFF,0x52,0x01, (byte) 0xFD, (byte) 0xDD}};
	//摩托一维码码制（关）
	private byte[][] motoSigValueClose = {{0x07,(byte) 0xC6,0x04,0x00,(byte) 0xFF,0x01,0x00,(byte) 0xFE,0x2F},{0x07,(byte) 0xC6,0x04,0x00,(byte) 0xFF,0x02,0x00,(byte) 0xFE,0x2E},
			{0x07,(byte) 0xC6,0x04,0x00,(byte) 0xFF,0x0C,0x00,(byte) 0xFE,0x24},{0x07,(byte) 0xC6,0x04,0x00,(byte) 0xFF,0x04,0x00,(byte) 0xFE,0x2C},{0x07,(byte) 0xC6,0x04,0x00,(byte) 0xFF,0x08,0x00,(byte) 0xFE,0x28},
			{0x07,(byte) 0xC6,0x04,0x00,(byte) 0xFF,0x00,0x00,(byte) 0xFE,0x30},{0x07,(byte) 0xC6,0x04,0x00,(byte) 0xFF,0x09,0x00,(byte) 0xFE,0x27},{0x07,(byte) 0xC6,0x04,0x00,(byte) 0xFF,0x0A,0x00,(byte) 0xFE,0x26},
			{0x07,(byte) 0xC6,0x04,0x00,(byte) 0xFF,0x06,0x00,(byte) 0xFE,0x2A},{0x07,(byte) 0xC6,0x04,0x00,(byte) 0xFF,0x07,0x00,(byte) 0xFE,0x29},{0x07,(byte) 0xC6,0x04,0x00,(byte) 0xFF,0x52,0x00,(byte) 0xFD,(byte) 0xDE}};

	//摩托罗拉二维码码制名称
	private String[] motoQRName = {"Data Marix","QR Code","MicroQR","PDF417","MicroPDF417","Matrix 2 of 5","Chinese 2 of 5"};
	private int[] motoQR_default = {0,1,0,1,0,0,0};
	//摩托罗拉二维码码制（打开）
	private byte[][] motoQRValueOpen = {{0x08, (byte) 0xC6,0x04,0x00,(byte) 0xFF,(byte) 0xF0,0x24,0x01,(byte) 0xFD,0x1A},{0x08,(byte) 0xC6,0x04,0x00,(byte) 0xFF,(byte) 0xF0,0x25,0x01,(byte) 0xFD,0x19},
			{0x08,(byte) 0xC6,0x04,0x00,(byte) 0xFF,(byte) 0xF1,0x3D,0x01,(byte) 0xFD,0x00},{0x07,(byte) 0xC6,0x04,0x00,(byte) 0xFF,0x0F,0x01,(byte) 0xFE,0x20},
			{0x07,(byte) 0xC6,0x04,0x00,(byte) 0xFF,(byte) 0xE3,0x01,(byte) 0xFD,0x4C},{0x08,(byte) 0xC6,0x04,0x00,(byte) 0xFF,(byte) 0xF1,0x6A,0x01,(byte) 0xFC,(byte) 0xD3},
			{0x08,(byte) 0xC6,0x04,0x00,(byte) 0xFF,(byte) 0xF0,(byte) 0x98,0x01,(byte) 0xFC,(byte) 0xA6}};
	//摩托罗拉二维码码制（关闭）
	private byte[][] motoQRValueClose = {{0x08,(byte) 0xC6,0x04,0x00,(byte) 0xFF,(byte) 0xF0,0x24,0x00,(byte) 0xFD,0x1B},{0x08,(byte) 0xC6,0x04,0x00,(byte) 0xFF,(byte) 0xF0,0x25,0x00,(byte) 0xFD,0x1A},
			{0x08,(byte) 0xC6,0x04,0x00,(byte) 0xFF,(byte) 0xF1,0x3D,0x00,(byte) 0xFD,0x01},{0x07,(byte) 0xC6,0x04,0x00,(byte) 0xFF,0x0F,0x00,(byte) 0xFE,0x21},
			{0x07,(byte) 0xC6,0x04,0x00,(byte) 0xFF,(byte) 0xE3,0x00,(byte) 0xFD,0x4D},{0x08,(byte) 0xC6,0x04,0x00,(byte) 0xFF,(byte) 0xF1,0x6A,0x00,(byte) 0xFC,(byte) 0xD4},
			{0x08,(byte) 0xC6,0x04,0x00,(byte) 0xFF,(byte) 0xF0,(byte) 0x98,0x00,(byte) 0xFC,(byte) 0xA7}};




    public static final String  KEY_POSTAL_2D   = "PostalCodes2D";
        
        
    List<BeanData> mListDataSig =  new ArrayList<BeanData>();
    List<BeanData> mListDataQR  =  new ArrayList<BeanData>();
	private static MyApplication application;
	private DaoHelper daoHelper;

	@Override
	public void onCreate() {
		super.onCreate();
        LogUtil.init(LogUtil.VERBOSE,"jsb_scanner");
		application = this;

		/**
		 * 第一次读取xml配置
		 */
		if(SharePreConfig.getIsFirstOpen()){
			BaseUtils.beanToString(xmlJiexi());
		}
	}

	public static MyApplication getApplication() {
		return application;
	}

	public List<BeanData> initSigData(){
	     	Log.e(Tag, "symbolsSig: "    + symbolsSig.length);
	     	Log.e(Tag, "commandsSig: " + commandsSig.length);
	     	
	     	mListDataSig.clear();
	  		SharedPreferences mSP = getSharedPreferences(SYMBOL_CONFIG_SIG, 0);
	  		
	    	 for(int i = 0; i < symbolsSig.length;  i++){
	    		 BeanData  mTemp =  new BeanData();
	    		 mTemp.setmSymbName(symbolsSig[i]);
	    		 mTemp.setmSubCommand(commandsSig[i]);
	    		 if(mSP.getBoolean(symbolsSig[i], false)){
	    			 mTemp.setOpened(true);	 
	    		 }
	    		 mListDataSig.add(mTemp);
	    	 }
	    	 
	    	return mListDataSig;
	}
	    
  public List<BeanData> initQRData(){

	     	mListDataQR.clear();
	  		SharedPreferences mSP = getSharedPreferences(SYMBOL_CONFIG_QR, 0);
	  		
	    	 for(int i = 0; i < symbolsQR.length;  i++){
	    		 BeanData  mTemp =  new BeanData();
	    		 mTemp.setmSymbName(symbolsQR[i]);
	    		 mTemp.setmSubCommand(commandsQR[i]);
	    		 if(mSP.getBoolean(symbolsQR[i], false)){
	    			 mTemp.setOpened(true);	 
	    		 }
	    		 mListDataQR.add(mTemp);
	    	 }
	    	 
	    	return mListDataQR;
    }

	/**
	 * 保存二维码
	 * @param symbols 维码制名称
	 * @param defaultCommands 维默认码制
	 * @param SP_KEY
	 */
	private void LoadFactorySettings(String[] symbols, String[] defaultCommands, String SP_KEY){
		
	         if(symbols.length  != defaultCommands.length){
	        	 Log.e(Tag, "LoadFactorySettings  fail");
	        	 return;
	         }
	         
	         SharedPreferences mSP = getSharedPreferences(SP_KEY, 0);//数据库名称
		  	 SharedPreferences.Editor editor = mSP.edit();
		  		
	         for( int i = 0;  i < defaultCommands.length;  i ++){
	        	 if(defaultCommands[i].endsWith("0.")){
			        editor.putBoolean(symbols[i], false); //将扫码的名称作为key,0.结尾的存false
	        	 }else{
	        		editor.putBoolean(symbols[i], true); 
	        	 }
	         }
	         
	         if( SP_KEY.equals(SYMBOL_CONFIG_QR) ){//二维码的时候
	        	 editor.putInt(KEY_POSTAL_2D, 0); 
	         }
	         
		  	 editor.commit();
	}
	
	public void LoadAllFactorySettings(){
	         LoadFactorySettings(symbolsSig, commandsSig_default, SYMBOL_CONFIG_SIG);
		     LoadFactorySettings(symbolsQR, commandsQR_default, SYMBOL_CONFIG_QR);
	}
	

	public void LoadAllMotoSetting(){
		if(daoHelper == null){
			daoHelper = new DaoHelper(this);
		}
		List<MotoBarcode> motoBars = daoHelper.getMotoBars();
		if(motoBars.isEmpty()){
			setSigMotoBean(motoSigName);
		}
		List<MotoQRBarcode> qrMotoBars = daoHelper.getQRMotoBars();
		if(qrMotoBars.isEmpty()){//保存二维码
			setQRMotoBean();
		}
	}

    private void setSigMotoBean(String[] value){
        for (int i = 0; i < value.length; i++) {
			if(motoSig_default[i] == 1){
				MotoBarcode barcode = new MotoBarcode();
				barcode.setCodeName(motoSigName[i]);
				barcode.setCodeOpenValue(motoSigValueOpen[i]);
				barcode.setCodeCloseValue(motoSigValueClose[i]);
				barcode.setCodeState(motoSig_default[i]);
				daoHelper.insert(barcode);
			}
        }
    }

	/**
	 * 二维码
	 */
	private void setQRMotoBean(){
		for (int i = 0; i < motoQRName.length; i++) {
			MotoQRBarcode qrBarcode = new MotoQRBarcode();
			qrBarcode.setQRcodeName(motoQRName[i]);
			qrBarcode.setQRcodeOpenValue(motoQRValueOpen[i]);
			qrBarcode.setQRcodeCloseValue(motoQRValueClose[i]);
			qrBarcode.setQRcodeState(motoQR_default[i]);
			daoHelper.insert(qrBarcode);
		}
	}


	/**
	 * 获取手机分辨率宽度
	 * metrics[1] = dm.heightPixels;
	 * @return
	 */
	public static int getPhoneWidthMetrics() {
		DisplayMetrics dm = new DisplayMetrics();
		WindowManager manager = (WindowManager) application.getSystemService(Context.WINDOW_SERVICE);
		assert manager != null;
		manager.getDefaultDisplay().getMetrics(dm);
		int widthPixels = dm.widthPixels;
		return widthPixels;
	}


	private String configPath = "vendor/etc/scanner_config.xml";
	/**
	 * 解析存在设备的xml获取配置信息
	 * @return
	 */
	public ScanSetting xmlJiexi(){
		ScanSetting scanSetting = new ScanSetting();
		BrocastButton brocastButton = null;
		List<BrocastButton> list = new ArrayList<>();
//        XmlResourceParser xml = getResources().getXml(R.xml.scanner_config);
		try {
            File file = new File(configPath);
            FileInputStream inputStream = new FileInputStream(file);
            XmlPullParser xml = Xml.newPullParser();
            xml.setInput(inputStream, "UTF-8");
			int eventType = xml.getEventType();
			while (eventType != XmlPullParser.END_DOCUMENT){
				String name = xml.getName();
				switch (eventType){
					case XmlPullParser.START_DOCUMENT:
						break;
					case XmlPullParser.START_TAG:
						if(name.equalsIgnoreCase("property")){
							String nameSetting = xml.getAttributeValue(0);
							String value = xml.getAttributeValue(1);
							LogUtil.i("xml解析数据=="+nameSetting+";attributeNamespace22=="+value);
							switch (nameSetting){
								case "model":
									scanSetting.setModel(value);
									break;
								case "openService_reboot":
									scanSetting.setOpenService_reboot(Boolean.parseBoolean(value));
									break;
								case "SerialPortName":
									scanSetting.setSerialPortName(value);
									break;
								case "FileNodePowerOn":
									scanSetting.setFileNodePowerOn(value);
									break;
								case "scanVoice":
									scanSetting.setScanVoice(Boolean.parseBoolean(value));
									break;
								case "scanVibrate":
									scanSetting.setScanVibrate(Boolean.parseBoolean(value));
									break;
								case "HIDChoose":
									scanSetting.setHIDChoose(Boolean.parseBoolean(value));
									break;
								case "EnterChoose":
									scanSetting.setEnterChoose(Boolean.parseBoolean(value));
									break;
								case "TabChoose":
									scanSetting.setTabChoose(value);
									break;
								case "ScanModel":
									scanSetting.setScanModel(value);
									break;
								case "FileNodeCloseOpen":
									scanSetting.setFileNodeCloseOpen(value);
									break;
								case "ScreenDirection":
									scanSetting.setScreenDirection(value);
									break;
								case "ClipBoardChoose":
									scanSetting.setClipBoardChoose(Boolean.parseBoolean(value));
									break;
								case "WidgetChoose":
									scanSetting.setWidgetChoose(Boolean.parseBoolean(value));
									break;
								case "SerialPortSwitch":
									scanSetting.setSerialPortSwitch(Boolean.parseBoolean(value));
									break;
								case "FileNodeChannelSwitch":
									scanSetting.setFileNodeChannelSwitch(value);
									break;
								case "FileNodeChannelValue":
									scanSetting.setFileNodeChannelValue(value);
									break;
								case "OpenScanValue":
									scanSetting.setOpenScanValue(value);
									break;
								case "CloseScanValue":
									scanSetting.setCloseScanValue(value);
									break;
								case "ScanModule":
									scanSetting.setScanModule(Integer.parseInt(value));
									if(Integer.parseInt(value) == Constans.DTHONEYWELL){
										SharePreConfig.setBaudRate(115200);
									}else {
										SharePreConfig.setBaudRate(9600);
									}
									break;
								default:
									break;
							}

						}
						if(name.equalsIgnoreCase("button")){
							brocastButton = new BrocastButton();
							String id = xml.getAttributeValue(0);
							brocastButton.setId(id);

						}
						if(brocastButton != null){
							if(name.equalsIgnoreCase("closeBroadcast")){
								String s = xml.nextText();
								brocastButton.setCloseBroadcast(s);
							}

							if("value".equalsIgnoreCase(name)){
								String value = xml.nextText();
								brocastButton.setValue(value);
							}
							if("openBroadcast".equalsIgnoreCase(name)){
								brocastButton.setOpenBroadcast(xml.nextText());
							}
						}

						break;
					case XmlPullParser.END_TAG:
						LogUtil.i("结尾的name=="+name);
						if (name.equals("button") && brocastButton !=null) {
							list.add(brocastButton);
							brocastButton = null;
						}
						if(name.equalsIgnoreCase("deviceCofing")){
							scanSetting.setBrocastButtons(list);
						}

						break;
				}
				eventType = xml.next();
			}
		} catch (XmlPullParserException e) {
			e.printStackTrace();
            LogUtil.e("解析xml=="+e.getMessage());
		} catch (IOException e) {
			e.printStackTrace();
			LogUtil.e("解析xml=="+e.getMessage());
		}
		return scanSetting;
	}

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);
    }
}